<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <title>Title</title>
</head>
<body>
<div id="app">
  <h1 >{{date}}</h1>
</div>
<script>
  new Vue({
    el:"#app",
    data(){
      return{
        date: new Date()
      }
    },
    created(){
      this.dateFormat(this.date);
    },
    methods:{
      dateFormat: function (data) {
        const year = data.getFullYear();
        /* 在日期格式中，月份是从0开始的，因此要加0
         * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
         * */
        const month = data.getMonth() + 1 < 10 ? "0" + (data.getMonth() + 1) : data.getMonth() + 1;
        const day = data.getDate() < 10 ? "0" + data.getDate() : data.getDate();
        const hours = data.getHours() < 10 ? "0" + data.getHours() : data.getHours();
        const minutes = data.getMinutes() < 10 ? "0" + data.getMinutes() : data.getMinutes();
        const seconds = data.getSeconds() < 10 ? "0" + data.getSeconds() : data.getSeconds();
        // 拼接
        this.date =  year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds;
        console.log(date)
      }
    }
  })
</script>
</body>
</html>